var selectUserId = "";
$(function() {

    /**
     * 保存按钮事件
     */
    $('#btn_save').on("click", function () {
        if($("#hdAcceptForm").form('validate')){
            layer.confirm("确定保存？",{btn:['确定','取消']},function(){
                var layerIndex=parent.layer.getFrameIndex(window.name); //获取窗口索引
                var data = $("#hdAcceptForm").serializeArray();
                console.log(data);
                $.ajax({
                    type:"POST",
                    url:ROOT_PATH + '/hiddenDanger/hdAccept/accept.shtml',
                    dataType:"json",
                    data:data,
                    success:function(result){
                        if (result.success){
                            layer.msg(result.message,{time:1000,icon:1},function(){
                                WindowManager.closeLayer({
                                    returnValue:""
                                });
                            });
                        }else{
                            layer.msg(result.message,{time:1000,icon:1},function(){
                                //parent.layer.close(layerIndex);
                            });
                        }
                    }
                });
            });
        }else{
            layer.msg("请按规则填写信息!",{time:1000,icon:2});
        }
    });


    /**
     * 绑定人员选择事件
     */
    $("#acceptUser").textbox({
        iconWidth: 15,
        icons: [{
            iconCls: 'icon-add',
            handler: function (e) {
                selectUserId = "acceptUser";
                add_contractorInfo_func();
            }
        }]
    });
});
/**
 * 定义表单验证
 */
$.extend($.fn.validatebox.defaults.rules, {
    minLength: {
        validator: function(value, param){
            return value.length >= param[0];
        },
        message: '最小长度'
    },
    intOrFloat: {// 验证整数或小数
        validator: function (value) {
            // alert(/^\d+(\.\d+)?$/i.test(value));
            return /^\d+(\.\d+)?$/i.test(value);
        },
        message: '请输入数字，并确保格式正确'
    },
    validSelect:{//验证为空字符串
        validator:function(value){
            //alert(value!="请选择");
            return value!="请选择"&&value!='';
        },
        message:'请选择'
    }

});
/**
 * 人员信息选择
 */
/*var getSelectedUser = function (data) {
   //给正常文本框赋值
    $("#"+selectUserId).textbox('setValue',data[0].name);
    $("#"+selectUserId+"Id").val(data[0].id);
    return data;
};*/
var add_contractorInfo_func = function () {
    WindowManager.openLayer({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
        callBack:function(data){
            //给正常文本框赋值
            $("#"+selectUserId).textbox('setValue',data[0].name);
            $("#"+selectUserId+"Id").val(data[0].id);
        }
    });
   /* layer.open({
        type: 2,
        title: '选择人员信息',
        area: ['1150px', '70%'],
        content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0'
    });*/
};